package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.exception.MallException;
import com.ymk.bo.goods.GoodsCartBO;
import com.ymk.core.code.cmd.GoodsCmdCode;
import com.ymk.service.IGoodsCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

@Service
public class GoodsCartPatchCmd extends ACmd {

    @Override
    public CmdSign executeStore(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        GoodsCartBO goodsCartBO = super.getData(sign, GoodsCartBO.class);

        super.setModifiedData(sign,goodsCartBO);
        this.goodsCartService.update(goodsCartBO);
        return respSign;
    }

    @Override
    public CmdSign verify(HttpServletRequest request, CmdSign sign) throws Exception {
        GoodsCartBO reqData = super.getData(sign, GoodsCartBO.class);
        if (Objects.isNull(reqData.getId())){
            throw new MallException("id为空");
        }
        return null;
    }

    @Override
    public String getCmdCode() {
        return GoodsCmdCode.GOODS_CART_PATCH;
    }

    @Autowired
    private IGoodsCartService goodsCartService;
}